﻿using System;
using System.Net;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Silverlight.Testing;

namespace MusicStore.WebService.Test
{
	public class TestBase : SilverlightTest
	{
		protected void WaitFor<T>(T objectToWaitForItsEvent, string eventName)
		{
			EventInfo eventInfo = objectToWaitForItsEvent.GetType().GetEvent(eventName);

			bool eventRaised = false;

			if (typeof(RoutedEventHandler).IsAssignableFrom(eventInfo.EventHandlerType))
				eventInfo.AddEventHandler(objectToWaitForItsEvent, (RoutedEventHandler)delegate { eventRaised = true; });
			else if (typeof(EventHandler).IsAssignableFrom(eventInfo.EventHandlerType))
				eventInfo.AddEventHandler(objectToWaitForItsEvent, (EventHandler)delegate { eventRaised = true; });

			EnqueueConditional(() => eventRaised);
		}
	}
}
